package org.hishenframework.tool.codegenerate.method;

import java.lang.reflect.Field;
import java.util.List;

import org.hishenframework.data.annotation.Label;

import freemarker.ext.beans.StringModel;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

/**
 * 成复数
 * @author ZhangDi
 *
 */
public class LabelTemplateMethodModelEx implements TemplateMethodModelEx {

	public Object exec(List arguments) throws TemplateModelException {
		Label label = null;
		Object o = ((StringModel)arguments.get(0)).getWrappedObject();
		if (o instanceof Class<?>) {
			Class<?> c = (Class<?>) o;
			label = c.getAnnotation(Label.class);
		} else {
			Field field = (Field) o;
			label = field.getAnnotation(Label.class);
		}
		if(label != null) {
			return label.value();
		}
		return "";
	}

}
